    //
    //  DetailViewController.m
    //  ZooNgonDoiOS
    //
    //  Created by Tran Minh Long on 8/7/12.
    //  Copyright (c) 2012 Personal. All rights reserved.
    //

#import "DetailViewController.h"
#import "DetailTableView.h"
#import "ZooSpotBean.h"
#import "HomeViewController.h"
#import "ListFoodViewController.h"
#import "CommentViewController.h"

@interface DetailViewController ()

@end

@implementation DetailViewController
@synthesize spotDetailDelegate;
@synthesize _spotBean;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
            // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
        // Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
        // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (id) initWithSpot: (ZooSpotBean*) zooSpotBean {
    
    self = [self initWithNibName:nil bundle:nil];
    
    if (self) {
        _screenSize = self.view.bounds.size;
        
        _spotBean = zooSpotBean;
        
        [self initHeaderView];
        [self initContent];
        [self initMenu];
    }
    
    return self;
}

- (void) initHeaderView {
    _vHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _screenSize.width, 48)];
    _vHeader.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:IMG_NAV_BACKGROUND]];
    
    _btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 48, 48)];
    [_btnBack setBackgroundImage:[UIImage imageNamed:IMG_BACK_NORMAL] forState:UIControlStateNormal];
    [_btnBack setBackgroundImage:[UIImage imageNamed:IMG_BACK_SELECTED] forState:UIControlStateHighlighted];
    [_btnBack addTarget:self action:@selector(backClicked) forControlEvents:UIControlEventTouchUpInside];
    
    _btnShare = [[UIButton alloc] initWithFrame:CGRectMake(_screenSize.width / 2, 0, _screenSize.width / 4, 48)];
    [_btnShare setBackgroundImage:[UIImage imageNamed:IMG_SHARE_NORMAL] forState:UIControlStateNormal];
    [_btnShare setBackgroundImage:[UIImage imageNamed:IMG_SHARE_SELECTED] forState:UIControlStateHighlighted];
    
    _btnCheckIn = [[UIButton alloc] initWithFrame:CGRectMake(_screenSize.width * 3/4, 0, _screenSize.width/4, 48)];
    [_btnCheckIn setBackgroundImage:[UIImage imageNamed:IMG_CHECKIN_NORMAL] forState:UIControlStateNormal];
    [_btnCheckIn setBackgroundImage:[UIImage imageNamed:IMG_CHECKIN_SELECTED] forState:UIControlStateHighlighted];
    
    [_vHeader addSubview:_btnBack];
    [_vHeader addSubview:_btnShare];
    [_vHeader addSubview:_btnCheckIn];
    
    [self.view addSubview:_vHeader];
    
    [_btnBack release];
    [_btnShare release];
    [_btnCheckIn release];
    [_vHeader release];
}

- (void) initContent {
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:IMG_VIEW_BACKGROUND]]];
    
        // The menu button doesn't stand in line.
    _vTableContent = [[DetailTableView alloc] initWithFrame:CGRectMake(0, 48, _screenSize.width, _screenSize.height - 85)];
    _vTableContent.tag = IDX_DETAIL_TABLEVIEW;
    _vTableContent._spotBean = _spotBean;
    [self.view addSubview:_vTableContent];
}

- (void) initMenu {
    
        // Init menu barse  zzzs3zzzzzz 1111
    _vMenuBar = [[UIView alloc] initWithFrame:CGRectMake(0, _screenSize.height - 39, _screenSize.width, 39)];
    _vMenuBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:IMG_MENU_BACKGROUND]];
    
        // Init menu button
    CGRect baseButtonPosition = CGRectMake(0, 0, _screenSize.width / 3, 39);
    baseButtonPosition.size.width += 3;
    
    _btnComment = [[UIButton alloc] initWithFrame:baseButtonPosition];
    [_btnComment setBackgroundImage:[UIImage imageNamed:IMG_COMMENT_NORMAL] forState:UIControlStateNormal];
    [_btnComment addTarget:self action:@selector(btnCommentClicked) forControlEvents:UIControlEventTouchUpInside];
    [_btnComment setBackgroundImage:[UIImage imageNamed:IMG_COMMENT_SELECTED] forState:UIControlStateHighlighted];
    
    baseButtonPosition.origin.x += _screenSize.width / 3;
    
    _btnMenu = [[UIButton alloc] initWithFrame:CGRectMake(baseButtonPosition.origin.x, baseButtonPosition.origin.y - 9, baseButtonPosition.size.width - 3, 48)];
    [_btnMenu setBackgroundImage:[UIImage imageNamed:IMG_MENU_NORMAL] forState:UIControlStateNormal];
    [_btnMenu setBackgroundImage:[UIImage imageNamed:IMG_MENU_SELECTED] forState:UIControlStateHighlighted];
    [_btnMenu addTarget:self action:@selector(btnMenuClicked) forControlEvents:UIControlEventTouchUpInside];
    
    baseButtonPosition.origin.x += _screenSize.width /3 - 3;
    
    _btnLike = [[UIButton alloc] initWithFrame:baseButtonPosition];
    [_btnLike setBackgroundImage:[UIImage imageNamed:IMG_LIKE_NORMAL] forState:UIControlStateNormal];
    [_btnLike setBackgroundImage:[UIImage imageNamed:IMG_LIKE_SELECTED] forState:UIControlStateHighlighted];
    
    [_vMenuBar addSubview:_btnComment];
    [_vMenuBar addSubview:_btnMenu];
    [_vMenuBar addSubview:_btnLike];
    
    [self.view addSubview:_vMenuBar];
    
    [_btnComment release];
    [_btnMenu release];
    [_vMenuBar release];
}

-(void)btnMenuClicked {
    ListFoodViewController *listFood = [[ListFoodViewController alloc]initWithObject:@"a"];
    [self presentModalViewController:listFood animated:YES];
}

-(void)btnCommentClicked {
    CommentViewController *commentView = [[CommentViewController alloc]init];
    [self presentModalViewController:commentView animated:YES];
}

    // Delegate function
- (void) backClicked {
        //    if (spotDetailDelegate != nil) {
        //        [spotDetailDelegate backToHomeView];
        //    }
    HomeViewController *homeViewController = [[HomeViewController alloc]init];
    [self.navigationController pushViewController:homeViewController animated:YES];
}

@end
